//
//  YZLSearchCarSecondView.m
//  Car
//
//  Created by dllo on 15/11/9.
//  Copyright © 2015年 岳明. All rights reserved.
//

#import "YZLSearchCarSecondView.h"
#import "YZLSubBrandListModel.h"
#import "Macro.h"

@interface YZLSearchCarSecondView ()

@property (nonatomic, strong) UIImageView *leftImageView;
@property (nonatomic, strong) UILabel *rightLabel;

@end

@implementation YZLSearchCarSecondView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:247 / 255.f green:247 / 255.f blue:247 / 255.f alpha:1];
        
        self.leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"A7"]];
        [self addSubview:self.leftImageView];
        
        self.rightLabel = [[UILabel alloc] init];
        [self addSubview:self.rightLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    
//    self.rightLabel = [[UILabel alloc] initWithFrame:CGRectZero]; //
    self.rightLabel.backgroundColor = [UIColor clearColor];
    self.rightLabel.frame = CGRectMake(15, 0, kWidth, 30);
    self.rightLabel.opaque = NO; //
    
    self.leftImageView.frame = CGRectMake(0, 0, 5, 30);
}

- (void)setSearchString:(NSString *)searchString {
    if (_searchString != searchString) {
        _searchString = searchString;
    }
    
    /* 高亮 */
    NSString *keyStr = [[_model.subBrandName stringByReplacingOccurrencesOfString:@"<font color=\"red\">" withString:@""] stringByReplacingOccurrencesOfString:@"</font>" withString:@""];

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:keyStr];
    NSRange range = [keyStr rangeOfString:searchString];
    
    [attributedString setAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:[UIFont systemFontOfSize:17]} range:range];
    self.rightLabel.attributedText = attributedString;


}

- (void)setModel:(YZLSubBrandListModel *)model {
    if (_model != model) {
        _model = model;
    }
  
   
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
